package business.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import vo.UserTopic;
import business.UserTopicService;
import dao.UserTopicDAO;

public class UserTopicServiceImpl implements UserTopicService {

	private UserTopicDAO userTopicDao;

	public List<UserTopic> getAllUserTopics() {
		return userTopicDao.findAll();
	}

	public boolean isExist(long userId, long topicId)
	{
		return userTopicDao.isExiste(userId,topicId);
	}

	public List<UserTopic> getNonSubUsers(long topicId) {
		return userTopicDao.findNonSubUsers(topicId);
	}

	public List<UserTopic> getUserTopicsByUserId(long userId) {
		return userTopicDao.findByUserId(userId);
	}

	public int getCountByUserId(long userId) {
		return userTopicDao.findCountByUserId(userId);
	}

	public List<UserTopic> getUserTopicsByTopicId(long topicId) {
		return userTopicDao.findByTopicId(topicId);
	}

	public List<UserTopic> getByTopicIdUserRole(long topicId) {
		return userTopicDao.findByTopicIdUserRole(topicId);
	}

	@Required
	public void setUserTopicDao(UserTopicDAO userTopicDao) {
		this.userTopicDao = userTopicDao;
	}

	@Transactional
	public void addUserTopic(String name) {
		UserTopic e = new UserTopic();
		userTopicDao.create(e);
	}

	@Transactional
	public void addUserTopic(UserTopic ut) {
		userTopicDao.create(ut);
	}

	@Transactional
	public UserTopic getById(long id) {
		return userTopicDao.getById(id);
	}

	@Transactional
	public void update(long id) {
		userTopicDao.update(id);
	}

	@Transactional
	public void delete(long id) {
		userTopicDao.delete(id);
	}

	public UserTopic getByTopicIdUserId(long topicId,long userId) {
		return userTopicDao.getByTopicIdUserId(topicId,userId);
	}

}